package com.wq.gof.designer.chain.list;

import java.util.Map;

/**
 * @Author: wangqiang20995
 * @Date:2019/1/25
 * @Description:
 * @Resource:
 */
public class MapEventHandler extends AbstractChainEventHandler {

    public MapEventHandler(HandlerContext handlerContext) {
        super(handlerContext);
    }

    @Override
    public void doHandle(Object conditions, HandlerContext handlerContext) {
        if (!(conditions instanceof Map)) {
            handlerContext.doHandler(conditions);
            return;
        }

        System.out.println("Map handler 处理请求");

        if (conditions == null) {
            System.out.println("Map handler --> empty map");
            return;
        }

        Map map = (Map) conditions;
        for (Object object : map.entrySet()) {
            Map.Entry entry = (Map.Entry) object;

            Object key = entry.getKey();
            Object value = entry.getValue();

            System.out.println("Map entry --> key/value [" + key.getClass().getName() + "/" + value.getClass().getName() + "]");
        }

        handlerContext.resume();
        return;
    }
}
